﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Resources;
using System.Globalization;
using BlueLotus7.Eden.Resource;

namespace BlueLotus7.Eden
{
    /// <summary>
    /// Resource Helper
    /// </summary>
    public static class LogMessageHelper
    {
        #region Private fields

        private static ResourceManager messages = EdenLogMessages.ResourceManager;

        #endregion

        #region Message Keys

        public const string OperationFailed_DataConflict = "OperationFailed_DataConflict";
        public const string OperationFailed_Unauthorized = "OperationFailed_Unauthorized";

        #endregion

        #region Public methods

        public static string GetMessageByKey(string key)
        {
            return messages.GetString(key);
        }

        public static string GetMessage(string key, params  object[] arguments)
        {
            return string.Format(messages.GetString(key), arguments);
        }

        public static string GetFailedOperationMessage(string operation, string targetObject)
        {
            return GetFailedOperationMessage(operation, targetObject, null);
        }

        public static string GetFailedOperationMessage(string operation, string targetObject, string data)
        {
            return GetOperationMessage(("ServiceOperationFailedMessageFormat"), operation, targetObject, data);
        }

        public static string GetSuccessedOperationMessage(string operation, string targetObject, string data)
        {
            return GetOperationMessage(("ServiceOperationSuccessedMessageFormat"), operation, targetObject, data);
        }

        public static string GetSuccessedOperationMessage(string operation, string targetObject)
        {
            return GetSuccessedOperationMessage(operation, targetObject, null);
        }

        #endregion

        #region Private methods

        public static string GetOperationMessage(string key, string operation, string targetObject, string data)
        {
            if (string.IsNullOrWhiteSpace(operation))
            {
                operation = "operate";
            }

            if (string.IsNullOrWhiteSpace(targetObject))
            {
                targetObject = string.Empty;
            }

            data = string.IsNullOrWhiteSpace(data) ? string.Empty : (" for: " + data);
            return string.Format(GetMessage(key), operation, targetObject, data);
        }


        #endregion
    }
}
